//选择通讯录
function selectDirPhone(va,formName,selectPhone){
//$.msgbox({height:450,width:450,content:{type:'iframe',content:''},title:'选择通讯录'});
}

//删除手机号码
function deletePhone(va){
	//alert("delete a phone"+va);
	$("#"+va+" option").each(function(){
		//alert("ddd"+$('#'+va+' option:selected').val());
		$('#'+va+' option:selected').remove();//delete the phone which selected
	});
}
//添加手机号码
function addPhone(formName,va){
	var phone = formName.phone.value;
	$("#"+va+" option").each(function(){
		
	});
	var bo = checkNum(phone)
	if(bo){
		var str = $("<option>"+phone+"</option>");
		str.appendTo("#"+va);
		formName.phone.value="";
		
	}
	//$("#"+va+".phone").attr("value","");
	//selectObj.innerText = 
}


//统计发送字数
function checkoverflowSM(formname,leng){
	var str = new String();
	str = formname.message.value;
	formname.counterMsg.value = leng - str.length;
	if (str.length>leng){
		formname.message.value = str.substr(0,leng);
		formname.counterMsg.value = 0;
		//alertmess('您输入的信息的长度应不超过'+leng+'!');
		return false;
	}
	return true;
}
function alertmess(alertmessage){
	$.msgbox({
		    width:300,
		    height:120,
	        content:{type:'alert', content:alertmessage},
	        animation:0,//禁止拖拽
	        drag:false,//禁止动画
	        autoClose: 5 //自动关闭
	    });
		return false;
}
//定时或及时发送
function isReceveSM(formname,bl,inTrName)
{
    if(bl)
	{
	  giveNowTimeSM(formname);
	  document.getElementById(inTrName).style.display='none';
	}else{
	  document.getElementById(inTrName).style.display='block';
	}
}

/*function userModule_checkForm(inForm){
	alert("标识"+inForm.biaoshi.value);
	var  flag=false;
	var tempObj="";
	if((trims(inForm.userName.value))==""){
		flag=true;
		tempObj=inForm.userName;
	}
	if((trims(inForm.userPass.value))==""){
		flag=true;
		tempObj=inForm.userPass;
	}
	if((trims(inForm.reUserPass.value))==""){
		flag=true;
		tempObj=inForm.reUserPass;
	}
	if((trims(inForm.userPhone.value))==""){
		flag=true;
		tempObj=inForm.userPhone;
	}
	if((trims(inForm.biaoshi.value))==""){
		flag=true;
		tempObj=inForm.biaoshi;
	}
	
	if(inForm.userPass.value!=inForm.reUserPass.value){
		$.msgbox({
			height:150,
	        width:250,
	        content:{type:'alert', content:'两次输入密码不一致!'},
	        animation:0,//禁止拖拽
	        drag:false,//禁止动画
	        autoClose: 5 //自动关闭
	    });
		inForm.userPass.value="";
		inForm.reUserPass.value="";
		inForm.userPass.focus();
		return false;
	}
	if(flag){
			$.msgbox({
				height:150,
		        width:250,
		        content:{type:'alert', content:tempObj.tip},
		        animation:0,//禁止拖拽
		        drag:false,//禁止动画
		        autoClose: 5 //自动关闭
		    });
			return false;
	}	
	return true;
}*/

/**
 *去空格
 */
function trims(inStr)
{
    return inStr.replace(/ /g,"");
}//end function trims

//全选功能
function selectAll(inName)
{
  var ckArray =  document.getElementsByName(inName);
  for(var i=0;i<ckArray.length;i++)
  {
	  ckArray[i].checked=ckArray[0].checked;
  }
}
//删除开始
function delRow(inPagePath,inCkName)
{
    var allIds="";
    var vslist = document.getElementsByName(inCkName);
	if(vslist.length<=0)
	{
		return false;
	}
	for(i=vslist.length-1;i>=0;i--)
	{
        if(vslist[i].checked)
        {    		      
		      if(allIds=="")
		      {
		    	  allIds=vslist[i].id;
		      }else{
		    	  allIds+=","+vslist[i].id;
		      }
		}//end if
		
	}//end for i
	if(trims(allIds).length==0)
	{
		$.msgbox({
			height:150,
	        width:250,
	        content:{type:'alert', content:'请选中后再删除'},
	        animation:0,//禁止拖拽
	        drag:false,//禁止动画
	        autoClose: 5 //自动关闭
	    });
		return false;
	}
	$.msgbox({
        height:150,
        width:250,
        content:{type:'confirm', content: '确定要删除吗?'},
        onClose:function(v){
            if(v) {window.location=inPagePath+"?allId="+allIds;}
            else return false;
        }
    });
	
}//end function delRow

function delRow(inPagePath,inCkName,inPram)
{
    var allIds="";
    var vslist = document.getElementsByName(inCkName);
	if(vslist.length<=0)
	{
		return false;
	}
	for(i=vslist.length-1;i>=0;i--)
	{
        if(vslist[i].checked)
        {    		      
		      if(allIds=="")
		      {
		    	  allIds=vslist[i].id;
		      }else{
		    	  allIds+="_"+vslist[i].id;
		      }
		}//end if
		
	}//end for i
	if(trims(allIds).length==0)
	{
		$.msgbox({
			height:150,
	        width:250,
	        content:{type:'alert', content:'请选中后再删除'},
	        animation:0,//禁止拖拽
	        drag:false,//禁止动画
	        autoClose: 5 //自动关闭
	    });
		return false;
	}
	$.msgbox({
        height:150,
        width:250,
        content:{type:'confirm', content: '确定要删除吗?'},
        onClose:function(v){
            if(v) {window.location=inPagePath+"?delAll="+allIds+"&"+inPram;}
            else return false;
        }
    });
	
}//删除结束


function userModule_checkForm(inForm){
	var flag=false;
	if((trims(inForm.userName.value))==""){
		flag=true;
		tempObj=inForm.userName;
	}
	if((trims(inForm.userPass.value))==""){
		flag=true;
		tempObj=inForm.userPass;
	}
	if((trims(inForm.reUserPass.value))==""){
		flag=true;
		tempObj=inForm.reUserPass;
	}
	
	if((trims(inForm.biaoshi.value))==""){
		flag=true;
		tempObj=inForm.biaoshi;
	}
	if((trims(inForm.reUserPass.value))!=(trims(inForm.userPass.value))){
		flag=true;
		tempObj=inForm.userPass;
	}
	if(flag){
	alert("用户名或密码、标识码不合法,请检查后再提交");
	tempObj.focus();
	return false;
	}
	return true;
}
function setIsView(inBl){
	document.getElementById('userType').value=inBl;
}//end function 
//select the sex of user when create a loginUser    0: man  1:wonman
function selectSex(va){
	document.getElementById("user_sex").value=va;
}


function doSubmit(typeId){
	var fenshu= $("#num").val();
	var strP=/^\d+(\.\d+)?$/; 
	if(!strP.test(fenshu))
	{
		alert("请输入整数!");
		return false;
	}
	window.parent.location="../DianboServlet?method=setSubmit&num="+fenshu+"&typeId="+typeId;
	top.msg.close();
}
function doSubmitDown(typeId){
	var fenshu= $("#num").val();
	var strP=/^\d+(\.\d+)?$/; 
	if(!strP.test(fenshu))
	{
		alert("请输入整数!");
		return false;
	}
	window.parent.location="../DianboServlet?method=setDownSubmit&num="+fenshu+"&typeId="+typeId;
	top.msg.close();
}
function doSubmitDownDati(typeId){
	var fenshu= $("#num").val();
	var strP=/^\d+(\.\d+)?$/; 
	if(!strP.test(fenshu))
	{
		alert("请输入整数!");
		return false;
	}
	window.parent.location="../DatiServlet?method=setDownSubmit&num="+fenshu+"&typeId="+typeId;
	top.msg.close();
}
function doSubmitXilie(xilieId){
	var fenshu= $("#num").val();
	var strP=/^\d+(\.\d+)?$/; 
	if(!strP.test(fenshu))
	{
		alert("请输入整数!");
		return false;
	}
	window.parent.location="../DatiServlet?method=setSubmit&num="+fenshu+"&xilieId="+xilieId;
	top.msg.close();
}

function addDatiType(url){
	var datiTypeName = $("#datiTypeName").val();
	var lastUrl = url+"&datiTypeName="+datiTypeName;
	var last_Url = encodeURI(lastUrl);
	last_Url=encodeURI(last_Url);
	window.location=last_Url;
}

function modifyDatiType(url){
	var datiTypeName = $("#datiTypeName").val();
	if(datiTypeName==""){
		alert("答题类型不能为空!");
		return ;
	}
	var lastUrl = url+"&datiTypeName="+datiTypeName;
	var last_Url = encodeURI(lastUrl);
	last_Url=encodeURI(last_Url);
	window.location=last_Url;
}

function deleteDatiType(url){
	//window.location=url;
	$.msgbox({
        height:150,
        width:250,
        content:{type:'confirm', content: '此操作会删除此类型下的所有系列及所有题目,确定要删除吗?'},
        onClose:function(v){
            if(v) {window.location=url;}
            else return false;
        }
    });
	
}
function addXilie(url){
	var xilieName = $("#xilieName").val();
	if(xilieName==""){
		alert("系列不能为空!");
		return ;
	}
	var lastUrl = encodeURI(url+"&xilieName="+xilieName);
	lastUrl = encodeURI(lastUrl);
	window.location=lastUrl;
}
function modifyDatiXilie(url){
	var xilieName = $("#datiXilieName").val();
	if(xilieName==""){
		alert("系列名列不能为空!");
		return ;
	}
	var lastUrl = encodeURI(url+"&xilieName="+xilieName);
	lastUrl = encodeURI(lastUrl);
	window.location=lastUrl;
}
function deleteXilie(url){
	//window.location = url;
	$.msgbox({
        height:150,
        width:250,
        content:{type:'confirm', content: '此操作会删除此系列下的所有题目,确定要删除吗?'},
        onClose:function(v){
            if(v) {window.location=url;}
            else return false;
        }
    });
}

function addDianboType(url){
	var dianboTypeName = $("#dianboTypeName").val();
	if(dianboTypeName==""){
		alert("名称不能为空!");
		return ;
	}
	var lastUrl = encodeURI(url+"&dianboTypeName="+dianboTypeName);
	lastUrl = encodeURI(lastUrl);
	window.location=lastUrl;
}
function modifyDianboType(url){
	var dianboTypeName = $("#dianboTypeName").val();
	if(dianboTypeName==""){
		alert("名称不能为空!");
		return ;
	}
	var lastUrl = encodeURI(url+"&dianboTypeName="+dianboTypeName);
	lastUrl = encodeURI(lastUrl);
	window.location= lastUrl;
}
function delDianboType(url){
	window.location= url;
}
//短信发送中的点点通
function upLoad(){
	var fileName = document.getElementById("fileName").value;
	//return false;
	var lastFileName = encodeURI(fileName);
	lastFileName = encodeURI(lastFileName);
	 var file_Name = fileName.split(".")[fileName.split(".").length-1];
	if(file_Name=="xls"||file_Name=="XLS"||file_Name=="txt"||file_Name=="TXT")
		 {
	 
	 }else
	 {
	 	alert("上传文件格式不对，请重新导入！");
	 	return ;
	 }
	 var url = "./TbSmsServlet?method=upLoad&filePath="+lastFileName;
	 fileForm.action=url;
	 fileForm.submit();
	
}
function selectDirPhone(va,formName,selectPhone){
	 /*var dir_Name=va.dir_Name.value;
	 var dirName = encodeURI(dir_Name);
	 dirName=encodeURI(dirName);*/
	 
	/* var quxian = encodeURI(qu_xian);
	 quxian = encodeURI(quxian);
	 
	 var hangye = encodeURI(hang_ye);
	 hangye = encodeURI(hangye);
	 
	 var qiye = encodeURI(qi_ye);
	 qiye = encodeURI(qiye);
	 
	 var bumen = encodeURI(bu_men);
	 bumen = encodeURI(bumen);*/
	// alert("come !!!!!!!");
	 var foName=formName;
	 frmMessage.mb=$.msgbox({height:450,width:800,content:{type:'iframe',content:'AddressServlet?method=selectDir&formName='+va.name+'&selectPhone='+selectPhone.name},title:'选择通讯录'});
}


function do_Submit(formName,selectPhone){
	 var select_dir = document.getElementsByName("select_Dir");
	 var dirId="";
	 var select_dirLen = select_dir.length;
	 for(var v = 0;v<select_dirLen;v++){
		 if(select_dir[v].checked){
			dirId+=select_dir[v].id+",";
			 select_dir[v].checked=false;
		 }
	 }
	 getLinkMan(formName,selectPhone,dirId);
}
//get linkMan by dirId    (1,2,3,.......)
function getLinkMan(formName,selectPhone,dirId){
	 var url = 'method=getLinkMans&dirId='+dirId+'&selectPhone='+selectPhone+'&formName='+formName+'&sessionId='+parseInt(Math.random()*(10000000));
	 var lastUrl = encodeURI(url);
	 lastUrl = encodeURI(lastUrl);
	// $.get(lastUrl,backFunction);
	 $.post('./AddressServlet',lastUrl,backFunction);
	
}
function backFunction(data){
	 var lastData =data.replace(/^\s+|\s+$/g,"");
	 var allData = lastData.split(",");
	 var formName = allData[0];
	 var first = allData[1];
	 var second = allData[2];
	// second.appendTo("#"+top.first);
	 if(second!=""){
		 top.back(first,second);
	 }
	
	 eval("top.frmMessage.mb.close();");
}
//往发送页面传手机号码
function back(selectPhone,dat){
		 var second = $(dat);
		 second.appendTo("#"+selectPhone);
   }

function addOrder(url){
	var orderType = $("#orderType").val();
	var typeId = $("#typeId").val();
	var orderName = $("#orderName").val();
	var lastUrl = url+"&orderName="+orderName+"&orderType="+orderType+"&typeId="+typeId;
	window.location = lastUrl;
}
function selectOrder(va){
	document.getElementById("typeId").value=va;
}

function modifyOrder(url){
	var orderName = $("#orderName").val();
	var lastUrl = encodeURI(url+"&orderName="+orderName);
	lastUrl =encodeURI(lastUrl);
	window.location=lastUrl;
}

function delOrder(url){
	window.location = url;
}
function setWuxiao(){
	var wuxiao = $("#wuxiao").val();
	var isreply=$("#thischeck").val();
	var url = "../TbOrderServlet?method=setWuxiao&wuxiao="+wuxiao+"&isreply="+isreply;
	var lastUrl = encodeURI(url);
	lastUrl = encodeURI(lastUrl);
	window.location=lastUrl;
}

function selec(va){
	if(va==0){//点播
		document.getElementById("dianbo").style.display="block";
		document.getElementById("dati").style.display="none";
	}else if(va==1){//答题
		document.getElementById("dianbo").style.display="none";
		document.getElementById("dati").style.display="block";
	}
}
//分拣短信时对此点播类型设置的分数查询
function selectDianbo(va){
	document.getElementById("dianbo_Type").value=va;
	$.post("./DianboTypeServlet","method=getValueByTypeId&typeId="+va,getDianboValue);
}
function getDianboValue(date){
	document.getElementById("dianboValue").value=date;
}
/**
 * 分拣短信时对答题类型设置的分数查询
 * @param va
 * @return
 */
function selectDati(va){
	document.getElementById("dati_Type").value=va;
	$.post("./DatiTypeServlet","method=getXilieByTypeId&typeId="+va,getXilieValue);
}
function getXilieValue(date){
	var lastDatte = decodeURIComponent(date);
	document.getElementById("xilie").style.display="block";
	document.getElementById("xilieList").innerHTML=lastDatte;
}

function selectXilie(va){
	document.getElementById("xilie_Type").value=va;
	$.post("./DatiTypeServlet","method=getXilieValue&xilieId="+va,getDatiValue)
}
function getDatiValue(date){
	document.getElementById("datiValue").value=date;
}
//分拣提交操作
function fenjiansubmit(url){
	var dianboOrDati = $("#dianboOrDati").val();//是点播还是答题 ？？
	var fenshu ;
	var phone ;
	if(dianboOrDati=="0"){//点播
		var dianbo_Type = $("#dianbo_Type").val();
		if(dianbo_Type=="0"){
			alert("请选择点播类型!");
			return null;
		}
		var newFenshu = $("#newDianboValue").val();
		var oldFenshu = $("#dianboValue").val();
		if(newFenshu==""){
			fenshu=oldFenshu;
		}else{
			fenshu=newFenshu;
		}
		phone =  $("#dianboPhone").val();
		var lastUrl = encodeURI(url+"&dianboOrDati=0&dianboType="+dianbo_Type+"&xilie_Type="+xilie_Type+"&phone="+phone+"&fenshu="+fenshu)
		lastUrl = encodeURI(lastUrl);
		window.location=lastUrl;
	}else if(dianboOrDati=="1")//答题
		{
			var dati_Type = $("#dati_Type").val();
			var xilie_Type = $("#xilie_Type").val();
			if(xilie_Type=="0"){
				alert("请选择答题类型及系列!");
				return null;
			}
			var newFenshu = $("#newDatiValue").val();
			var oldFenshu = $("#datiValue").val();
			if(newFenshu==""){
				fenshu=oldFenshu;
			}else{
				fenshu=newFenshu;
			}
			phone =  $("#datiPhone").val();
			var lastUrl = encodeURI(url+"&dianboOrDati=1&dati_Type="+dati_Type+"&xilie_Type="+xilie_Type+"&phone="+phone+"&fenshu="+fenshu)
			lastUrl = encodeURI(lastUrl);
			window.location=lastUrl;
		}
}

function fenjian(url){
	var lastUrl = encodeURI(url);
	lastUrl = encodeURI(lastUrl);
	form1.msg=$.msgbox({
        height:400,
        width:500,
        content:{type:'ajax', content:lastUrl},
        title: '短信分拣'
    });
}

function selectJifenType(va){
	if(va=="0"){
		document.getElementById("1").style.display="none";
		document.getElementById("0").style.display="block";
	}else if(va=="1"){
		document.getElementById("0").style.display="none";
		document.getElementById("1").style.display="block";
	}
}

//根据条件查询答题记录
function searcherByDati(url){
	var datitype = $("#datitype").val();
	var content = $("#content").val();
	var lastUrl = encodeURI(url+"&datitype="+datitype+"&content="+content);
	lastUrl = encodeURI(lastUrl);
	window.location=lastUrl;
}
//新增答题
function addDati(){
	var dati_Type = formadd.dati_Type.value;
	var xilie_Type = formadd.xilie_Type.value;//系列的ID
	var daticontent = formadd.daticontent.value;
	var datianswer = formadd.datianswer.value;
	
	if(dati_Type=="0"){
		alert("请选择答题类型!");
		return null;
	}
	if(xilie_Type=="0"){
		alert("请选择系列!");
		return null;
	}
	if(datianswer==""){
		alert("请输入答案!");
		return null;
	}
	
	if(daticontent==""){
		alert("请输入答题!");
		return null;
	}
	var url = "../DatiServlet?method=addDati&datiType="+dati_Type+"&xilieType="+xilie_Type+"&datianswer="+datianswer+"&daticontent="+daticontent;
	var lastUrl = encodeURI(url);
	lastUrl = encodeURI(lastUrl);
	window.location=lastUrl;
}
function deleteOneDati(url){
	var lastUrl = encodeURI(url);
	lastUrl = encodeURI(lastUrl);
	window.location=lastUrl;
}
